﻿(function(window){
	var offset = 174,
		numb = 3,
		i = 0;
	
	
	var slide = function(ol,liset){
		this.ol = ol;
		this.liset = liset;
		this.next = 1;
		this.card = true;
		
		this.init().move();
	};
	
	slide.prototype = {
		init: function(){
			this.ol.style.position = 'absolute';
			
			var _this = this;
			for(;i<numb;i++){
				this.liset[i]['id'] = i;
				
				addEvent(this.liset[i],'mouseover',function(){
					if(_this.handle)
						window.clearTimeout(_this.handle);
					_this.liset[_this.next-1].className = '';
					_this.next = this.id;
					_this.card = false;
					_this.step();
				});
				
				addEvent(_this.liset[i],'mouseout',function(){
					_this.card = true;
					_this.step();
				});
			}
			return this;
		},
		
		move: function(){
			var _this = this;
			this.handle = 
				window.setTimeout(function(){
					_this.step();
				},3*1000);
		},
		
		step: function(){
			
			if(this.next >= numb){
				this.next = 0;
				this.ol.style.top = 0;
			}else{
				this.ol.style.top = (0 - this.next * offset) + 'px';
			}
			
			if(this.next - 1 >= 0){
				this.liset[this.next-1].className = '';
				this.liset[this.next].className = 'current';
			}else{
				this.liset[numb-1].className = '';
				this.liset[0].className = 'current';
			}
			
			if(this.card){
				this.next++;
				this.move();
			}
		}
	};
	
	var sloo = function(ol,liset){
		return new slide(ol,liset);
	};
	
	window.sloo = sloo;
})(window);